﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default6 : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getData();
        }
    }

    private void getData()
    {
        string strTemp1 = string.Empty;
        string strTemp2 = string.Empty;

        if (string.IsNullOrEmpty(strType))
        {
            strTemp1 = @"<a href=""Default6.aspx?Type=0&{0}"" title=""{1}"" class=""r1_c_current"">{1}</a>";
            strTemp2 = @"<a href=""Default6.aspx?Type=0&{0}"" title=""{1}"" class=""r1_c_currenta"">{1}</a>";
        }
        else
        {
            strTemp1 = @"<a href=""Default6.aspx?Type=" + strType + @"&{0}"" title=""{1}"" class=""r1_c_current"">{1}</a>";
            strTemp2 = @"<a href=""Default6.aspx?Type=" + strType + @"&{0}"" title=""{1}"" class=""r1_c_currenta"">{1}</a>";
            if (int.Parse(strType) == 0)
            {
                litType.Text = @"<a href=""Default6.aspx?type=0"" title=""经纪人"" class=""r1_c_current"">经纪人</a><a href=""Default6.aspx?type=1"" title=""中介门店"" class=""r1_c_currentda"">中介门店</a></asp:Literal>";
            }
            else
            {
                litType.Text = @"<a href=""Default6.aspx?type=0"" title=""经纪人"" class=""r1_c_currentda"">经纪人</a><a href=""Default6.aspx?type=1"" title=""中介门店"" class=""r1_c_current"">中介门店</a></asp:Literal>";
            }
        }
                

        //全部着色
        if (string.IsNullOrEmpty(strArea))
        {
            lbtnALL2.CssClass = lbtnALL3.CssClass = "r1_c_current";

        }
        else
        {
            if (string.IsNullOrEmpty(strMinArea)) lbtnALL3.CssClass = "r1_c_current";
        }

        //获取行业信息
        string strFinType = string.Empty;
        DataTable dtbDict = DtArea();
        foreach (DataRow dr in dtbDict.Rows)
        {
            if (dr[0].ToString() == strArea)
            {
                strFinType += string.Format(strTemp1, "AreaID=" + dr[0].ToString(), dr[1].ToString());
            }
            else
            {
                strFinType += string.Format(strTemp2, "AreaID=" + dr[0].ToString(), dr[1].ToString());
            }
        }

        LitArea.Text = strFinType;
        //获取公司信息
        string strCompany = string.Empty;
        if (!string.IsNullOrEmpty(strArea))
        { 
            DataTable dtMinArea = new DataTable();
            dtMinArea = DtMinArea(int.Parse(strArea));

            foreach (DataRow dr in dtMinArea.Rows)
            {
                if (dr[0].ToString() == strMinArea)
                {
                    strCompany += string.Format(strTemp1, "AreaID=" + dr[1].ToString() + "&MinAreaID=" + dr[0].ToString(), dr[2].ToString());
                }
                else
                {
                    strCompany += string.Format(strTemp2, "AreaID=" + dr[1].ToString() + "&MinAreaID=" + dr[0].ToString(), dr[2].ToString());
                }
            }
        }
        LitMinArea.Text = strCompany;
    }


    private DataTable DtArea()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("AreaName");

        string[] a = new string[12] { "园区", "新区", "平江", "沧浪", "金闾", "吴中", "相城", "吴江", "昆山", "太仓", "常熟", "张家港" };

        for (int i = 0; i < 12; i++)
        {
            DataRow dr = dt.NewRow();
            dr[0] = i;
            dr[1] = a[i];

            dt.Rows.Add(dr);
        }

        return dt;
    }

    private DataTable DtMinArea(int AreaID)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("AreaID");
        dt.Columns.Add("MinAreaName");

        string[] a = new string[8] { "东环路", "娄葑", "湖东", "湖西", "独墅湖", "胜浦", "唯亭", "青剑湖" };
        string[] b = new string[9] { "狮山", "横塘", "阳山", "浒墅关", "通安", "东渚", "镇湖", "科技城", "枫桥" };
        string[] c = new string[6] { "桃花坞", "平江路", "娄门", "城北街道", "苏锦街道", "观前" };

        if (AreaID == 0)
        {
            for (int i = 0; i < 8; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = i;
                dr[1] = 0;
                dr[2] = a[i];

                dt.Rows.Add(dr);
            }
        }
        else if (AreaID == 1)
        {
            for (int i = 0; i < 9; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = i + 8;
                dr[1] = 1;
                dr[2] = b[i];
                dt.Rows.Add(dr);
            }
        }
        else
        {
            for (int i = 0; i < 6; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = i + 17;
                dr[1] = 2;
                dr[2] = c[i];
                dt.Rows.Add(dr);
            }
        }

        return dt;
  
 
    }

    protected void lbtnALL2_Click(object sender, EventArgs e)
    {
        string strUrl = "Default6.aspx";
        if (!string.IsNullOrEmpty(strType))
        {
            strUrl += "?Type=" + strType;
        }
        else
        {
            strUrl += "?Type=0";
        }
        Response.Redirect(strUrl);
    }

    protected void lbKeySearch_Click(object sender, EventArgs e)
    {
        string strUrl = "Default6.aspx?Type=0";
        strUrl += "&SearchKey=" + tbkey.Text;
        Response.Redirect(Server.HtmlEncode(strUrl));
    }

    protected void lbtnALL3_Click(object sender, EventArgs e)
    {
        string strUrl = "Default6.aspx";
        if (!string.IsNullOrEmpty(strType))
        {
            strUrl += "?Type=" + strType;
        }
        else
        {
            strUrl += "?Type=0";
        }
        if (!string.IsNullOrEmpty(strArea))
        {
            strUrl += "&AreaID=" + strArea;
        }
        Response.Redirect(strUrl);
    }


    protected string RequestURL(string p_strID)
    {
        if (Request[p_strID] != null && Request[p_strID].ToString().Trim() != string.Empty)
        {
            return Request[p_strID].ToString().Trim();
        }
        else
        {
            return string.Empty;
        }
    }

    #region 属性
    protected string strType
    {
        get
        {
            return this.RequestURL("TYPE").ToString();
        }
    }

    protected string strArea
    {
        get
        {
            return this.RequestURL("AreaID").ToString();
        }
    }

    protected string strMinArea
    {
        get
        {
            return this.RequestURL("MinAreaID").ToString();
        }
    }

    #endregion

}
